{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第五次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer5文件夹下，**谢绝交到master下**\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在11月7日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名  \n",
    "+ 学号"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "吴雨婷\n",
    "0165211"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一、贫困户模型\n",
    "+ 创建一个类，包含贫困户的义务教育保障、住房安全、饮水安全、肉蛋奶豆的四个属性\n",
    "+ 包含一个是否贫困的预测，如果四个属性有两个以上没有保障（>2)则输出为贫困户\n",
    "+ 对贫困户，采取相应措施（输入参数）对其进行帮扶，使其脱贫\n",
    "+ 至少生成三个实例\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "贫困户\n",
      "需要帮扶义务教育保障\n",
      "需要帮扶住房安全\n",
      "需要帮扶饮水安全\n",
      "\n",
      "\n",
      "非贫困户\n",
      "\n",
      "不需要帮扶\n",
      "\n",
      "\n",
      "非贫困户\n",
      "\n",
      "不需要帮扶\n"
     ]
    }
   ],
   "source": [
    "class poor(object):\n",
    "    def __init__(self,x1,x2,x3,x4): ## 需要定义传递的值\n",
    "        self.education=x1\n",
    "        self.house=x2\n",
    "        self.water=x3\n",
    "        self.nutrition=x4\n",
    "    def access(self):          \n",
    "        sum = 0\n",
    "        if self.education:\n",
    "            sum += 1 \n",
    "        if self.house:\n",
    "            sum += 1\n",
    "        if self.water:\n",
    "            sum += 1\n",
    "        if self.nutrition:\n",
    "            sum += 1\n",
    "        if sum<2:\n",
    "            print('贫困户')         \n",
    "        else:\n",
    "            print('非贫困户')\n",
    "            \n",
    "    def assist(self):\n",
    "        sum = 0\n",
    "        if self.education:\n",
    "            sum += 1 \n",
    "        if self.house:\n",
    "            sum += 1\n",
    "        if self.water:\n",
    "            sum += 1\n",
    "        if self.nutrition:\n",
    "            sum += 1\n",
    "        if sum<2:\n",
    "            if self.education==False:\n",
    "                print(\"需要帮扶义务教育保障\")\n",
    "            if self.house == False:\n",
    "                print(\"需要帮扶住房安全\")\n",
    "            if self.water  == False:\n",
    "                print(\"需要帮扶饮水安全\")\n",
    "            if self.nutrition == False:\n",
    "                print(\"需要帮扶肉蛋奶肉\")\n",
    "        else:\n",
    "            print(\"\\n不需要帮扶\")\n",
    "\n",
    "family1=poor(False,False,False,True) \n",
    "family1.access()\n",
    "family1.assist()\n",
    "\n",
    "print('\\n')\n",
    "family2=poor(True,False,False,True)\n",
    "family2.access()\n",
    "family2.assist()\n",
    "\n",
    "\n",
    "print('\\n')\n",
    "family3=poor(True,True,True,True)\n",
    "family3.access()\n",
    "family3.assist()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二: 学生信息\n",
    "+ 创建一个类，包含姓名、分数、睡眠时间三个属性\n",
    "+ 包含一个胖瘦的预测，如果分数>90，且睡眠时间少于6小时，输出“BMI可能偏大”，否则输出“体重正常”\n",
    "+ 为使得标准（90分、6小时）可以调整，标准应设为输入的参数\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'BMI可能偏大'"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class Student(object):\n",
    "    def __init__(self, name, score,sleep):\n",
    "            self.name = name\n",
    "            self.score = score\n",
    "            self.sleep = sleep\n",
    "    def get_grade(self,c1,c2):           ##为使得标准（90分、6小时）可以调整，标准应设为输入的参数\n",
    "        if (self.score>c1)&(self.sleep <c2):\n",
    "            return 'BMI可能偏大'\n",
    "        else:\n",
    "            return '体重正常'\n",
    "    \n",
    "    \n",
    "    \n",
    "stu1 = Student('黄飞鸿',100,6)\n",
    "stu1.get_grade(99,8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'体重正常'"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu2 = Student('韩梅梅', 89,8)\n",
    "stu2.get_grade(90,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'体重正常'"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu3= Student('林黛玉',80,9)\n",
    "stu3.get_grade(90,10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三：“跑步社”成员类\n",
    "+ 创建一个“跑步社”成员类，以学生信息类为父类\n",
    "+ 添加一个属性为跑步\n",
    "+ 如果跑步时间大于30分钟，如果之前预测为“BMI可能偏大”，则输出为“趋向正常”\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'趋向正常'"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class running_club(Student):       ##创建一个“跑步社”成员类，以学生信息类为父类\n",
    "   \n",
    "    def __init__(self, name,score,sleep,running_time):        ##添加一个属性为跑步\n",
    "        super().__init__(name,score,sleep)                      ## 通过super函数声明继承了父类的属性\n",
    "        self.running_time = running_time\n",
    "    def get_grade(self,c1,c2):\n",
    "        if (self.score>c1)&(self.sleep <c2):\n",
    "            if self.running_time>30:\n",
    "                return '趋向正常'          ##如果跑步时间大于30分钟，如果之前预测为“BMI可能偏大”，则输出为“趋向正常”\n",
    "            else:\n",
    "                return 'BMI可能偏大'\n",
    "        else:\n",
    "            return '体重正常'\n",
    "    \n",
    "            \n",
    "\n",
    "    \n",
    "stu4=running_club('小龙女',91,6,40)\n",
    "stu4.get_grade(90,8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'体重正常'"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu5=running_club('小明',91,8,40)\n",
    "stu5.get_grade(90,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'BMI可能偏大'"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu4=running_club('小龙女',91,6,23)\n",
    "stu4.get_grade(90,8)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
